package com.example.mynews;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;

import com.example.mynews.UI.Guide;
import com.example.mynews.UI.Index;

public class MainActivity extends AppCompatActivity {

    private LinearLayout layout;
    private boolean isFristUserAPP = false; // 是否是第一次进入程序
    private SharedPreferences share; // 用于保存isFristUserAPP

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        layout = (LinearLayout) findViewById(R.id.layout);
        share = getSharedPreferences("isFristUserAPP", MODE_PRIVATE);
        isFristUserAPP = share.getBoolean("isFristUserAPP", true);
        Animation animation= AnimationUtils.loadAnimation(MainActivity.this, R.anim.view_anim);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (isFristUserAPP)
                {
                    startActivity(new Intent(MainActivity.this, Guide.class));
                    finish();
                    SharedPreferences.Editor edit = share.edit();
                    edit.putBoolean("isFristUserAPP",false);
                    edit.commit();
                    finish();
                }else
                {
                    startActivity(new Intent(MainActivity.this, Index.class));
                    finish();
                }
            }
            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        layout.startAnimation(animation);
    }
}